{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [],
   "source": [
    "from openai import OpenAI\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from dotenv import load_dotenv\n",
    "import os\n",
    "load_dotenv()\n",
    "api_key = os.environ.get(\"DASHSCOPE_API_KEY\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": [
    "client = OpenAI(api_key=api_key, base_url=\"https://api.deepseek.com/v1\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_completion(prompt, model=\"deepseek-chat\"):\n",
    "    response = client.chat.completions.create(\n",
    "    model = model,\n",
    "    messages=[\n",
    "        {\"role\": \"system\", \"content\": prompt},\n",
    "    ],\n",
    "    stream=False\n",
    ")\n",
    "    print(response.choices[0].message.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1+1 的结果取决于你所处的数学体系或上下文。以下是几种常见情况：\n",
      "\n",
      "1. **十进制算术**：在标准算术中，1 + 1 = 2。\n",
      "2. **二进制系统**：在二进制中，1 + 1 = 10（读作“一零”，表示十进制中的2）。\n",
      "3. **布尔代数**：在逻辑运算中，1 + 1 通常表示“逻辑或”（OR），结果为1（真）。\n",
      "4. **模2运算（异或）**：在模2加法中（例如计算机中的异或操作），1 + 1 = 0。\n",
      "5. **其他上下文**：\n",
      "   - 在集合论中，1 + 1 可能表示两个单元素集合的并集，其基数可能为1（如果元素相同）或2（如果不同）。\n",
      "   - 在化学中，1升水加1升酒精可能得到小于2升的混合物（由于分子间空隙）。\n",
      "   - 在哲学或玩笑中，可能有“1+1=11”（拼接）或“1+1=1”（如一滴水加一滴水）等说法。\n",
      "\n",
      "**最常见答案**：在数学和日常计算中，**1 + 1 = 2**。\n"
     ]
    }
   ],
   "source": [
    "get_completion(\"1+1等于几？\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "custom_email = \"\"\"\n",
    "I be fuming that me blender lid flew off and splattered me kitchen walls with smoothie! And to make matters worse, the warranty dont't cover the cost of cleaning up me kitchen. I need yer help right now, matey!\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "style = \"\"\"\n",
    "American English in a clam and respectful tone\n",
    "\"\"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = f\"\"\"\n",
    "Translate the text that is delimited by triple backticks into a style that is {style}. text: ```{custom_email}```\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Of course. Here is the text translated into a calm and respectful style of American English:\n",
      "\n",
      "I am quite upset that the lid of my blender came off and splattered smoothie all over my kitchen walls. To make matters worse, the warranty does not cover the cost of cleaning my kitchen. I would appreciate your assistance at your earliest convenience.\n"
     ]
    }
   ],
   "source": [
    "get_completion(prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 使用LangChain 执行上面的操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_openai import ChatOpenAI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ChatOpenAI(client=<openai.resources.chat.completions.completions.Completions object at 0x7a484b3ff8c0>, async_client=<openai.resources.chat.completions.completions.AsyncCompletions object at 0x7a484b3ff650>, root_client=<openai.OpenAI object at 0x7a484b3febd0>, root_async_client=<openai.AsyncOpenAI object at 0x7a484b3ff050>, model_name='deepseek-chat', model_kwargs={}, openai_api_key=SecretStr('**********'), openai_api_base='https://api.deepseek.com/v1')"
      ]
     },
     "execution_count": 159,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chat  = ChatOpenAI(api_key=\"sk-a7eff63e5dca4ec791af9550e7b01d3f\", base_url=\"https://api.deepseek.com/v1\",model=\"deepseek-chat\")\n",
    "chat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [],
   "source": [
    "template_string = \"\"\"\n",
    "Translate the text that is delimited by triple backticks into a style that is {style}. text: ```{text}```\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.prompts import ChatPromptTemplate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 创建提示词模板\n",
    "prompt_template = ChatPromptTemplate.from_template(template_string)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PromptTemplate(input_variables=['style', 'text'], input_types={}, partial_variables={}, template='\\nTranslate the text that is delimited by triple backticks into a style that is {style}. text: ```{text}```\\n')"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prompt_template.messages[0].prompt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [],
   "source": [
    "style = \"\"\"\n",
    "American English in a clam and respectful tone\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {},
   "outputs": [],
   "source": [
    "custom_email = \"\"\"\n",
    "I be fuming that me blender lid flew off and splattered me kitchen walls with smoothie! And to make matters worse, the warranty dont't cover the cost of cleaning up me kitchen. I need yer help right now, matey!\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [],
   "source": [
    "custom_message = prompt_template.format_messages(style = style, text = custom_email)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Translate the text that is delimited by triple backticks into a style that is \n",
      "American English in a clam and respectful tone\n",
      ". text: ```\n",
      "I be fuming that me blender lid flew off and splattered me kitchen walls with smoothie! And to make matters worse, the warranty dont't cover the cost of cleaning up me kitchen. I need yer help right now, matey!\n",
      "```\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(custom_message[0].content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = chat.invoke(custom_message)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Of course. Here is the text translated into a calm and respectful tone in American English:\n",
      "\n",
      "```\n",
      "I am very frustrated that my blender lid flew off and splattered my kitchen walls with smoothie. To make matters worse, the warranty does not cover the cost of cleaning my kitchen. I would appreciate your assistance with this matter.\n",
      "```\n"
     ]
    }
   ],
   "source": [
    "print(response.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "metadata": {},
   "outputs": [],
   "source": [
    "service_reply = \"\"\"Hey there customer, \\\n",
    "    the warraanty does not cover \\\n",
    "    cleaning expense for your kitchen \\\n",
    "    because it's your fault that \\\n",
    "    by forgetting to put the lid on before \\\n",
    "    starting the blender. \\\n",
    "    Tough luck! See ya!\n",
    "        \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [],
   "source": [
    "service_style_private = \"\"\"\\\n",
    "a polite tone \\\n",
    "that speaks in English Pirate\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Translate the text that is delimited by triple backticks into a style that is a polite tone that speaks in English Pirate. text: ```Hey there customer,     the warraanty does not cover     cleaning expense for your kitchen     because it's your fault that     by forgetting to put the lid on before     starting the blender.     Tough luck! See ya!\n",
      "        ```\n",
      "\n"
     ]
    }
   ],
   "source": [
    "service_message = prompt_template.format_messages(style=service_style_private,text=service_reply)\n",
    "print(service_message[0].content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ahoy there, valued customer!\n",
      "\n",
      "Me apologies, but the warranty be not coverin' the costs o' cleanin' yer galley. 'Tis on account o' the unfortunate circumstance o' forgettin' to secure the lid afore ye set the blender to sail.\n",
      "\n",
      "A true shame, that be. May fair winds find ye on yer next voyage!\n",
      "\n",
      "Fare thee well\n"
     ]
    }
   ],
   "source": [
    "response = chat.invoke(service_message)\n",
    "print(response.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 输出JSON并解析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'gift': False, 'delivery_days': 5, 'price_value': 'pretty affordable!'}"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "{\n",
    "    \"gift\":False,\n",
    "    \"delivery_days\": 5,\n",
    "    \"price_value\":\"pretty affordable!\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "metadata": {},
   "outputs": [],
   "source": [
    "custom_review = \"\"\"\\\n",
    "这款吹页机非常神奇。它有四个设置：\\\n",
    "    吹蜡烛、微风、风城、龙卷风。\\\n",
    "        两天后就到了，正好赶上我妻子的\\\n",
    "            两周年纪念礼物。\\\n",
    "                我想我的妻子会喜欢它到说不出来话。\\\n",
    "                    到目前为止，我是唯一一个使用过它的人，而且我一直\\\n",
    "                        每隔一天早上用它来清理草坪上的叶子。\\\n",
    "                            它比其他吹页机稍贵一点，\\\n",
    "                                但我认为它的额外功能是值得的。\"\"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [],
   "source": [
    "review_template = \"\"\"\\\n",
    "对于以下文本，请从中提取以下信息：\\\n",
    "    \n",
    "礼物：该商品是作为礼物送给别人的吗？\\\n",
    "如果是，则回答 是的；如果否或未知，则回答不是。\n",
    "\n",
    "交货天数：产品需要多少天到达？如果没有找到该信息，则输出-1。\n",
    "\n",
    "价钱：提取有关价值或价格的任何句子，并将它们输出为逗号分割的python列表。\n",
    "\n",
    "请使用以下键，将输出格式化为JSON：\n",
    "礼物\n",
    "交货天数\n",
    "价钱\n",
    "\n",
    "文本: {text}\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "提示模板： input_variables=['text'] input_types={} partial_variables={} messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['text'], input_types={}, partial_variables={}, template='对于以下文本，请从中提取以下信息：\\n礼物：该商品是作为礼物送给别人的吗？如果是，则回答 是的；如果否或未知，则回答不是。\\n\\n交货天数：产品需要多少天到达？如果没有找到该信息，则输出-1。\\n\\n价钱：提取有关价值或价格的任何句子，并将它们输出为逗号分割的python列表。\\n\\n请使用以下键，将输出格式化为JSON：\\n礼物\\n交货天数\\n价钱\\n\\n文本: {text}'), additional_kwargs={})]\n"
     ]
    }
   ],
   "source": [
    "prompt = ChatPromptTemplate.from_template(review_template)\n",
    "print(\"提示模板：\",prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对于以下文本，请从中提取以下信息：\n",
      "礼物：该商品是作为礼物送给别人的吗？如果是，则回答 是的；如果否或未知，则回答不是。\n",
      "\n",
      "交货天数：产品需要多少天到达？如果没有找到该信息，则输出-1。\n",
      "\n",
      "价钱：提取有关价值或价格的任何句子，并将它们输出为逗号分割的python列表。\n",
      "\n",
      "请使用以下键，将输出格式化为JSON：\n",
      "礼物\n",
      "交货天数\n",
      "价钱\n",
      "\n",
      "文本: 这款吹页机非常神奇。它有四个设置：    吹蜡烛、微风、风城、龙卷风。        两天后就到了，正好赶上我妻子的            两周年纪念礼物。                我想我的妻子会喜欢它到说不出来话。                    到目前为止，我是唯一一个使用过它的人，而且我一直                        每隔一天早上用它来清理草坪上的叶子。                            它比其他吹页机稍贵一点，                                但我认为它的额外功能是值得的。\n"
     ]
    }
   ],
   "source": [
    "message = prompt.format_messages(text = custom_review)\n",
    "print(message[0].content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = chat.invoke(message)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"礼物\": \"是的\",\n",
      "  \"交货天数\": 2,\n",
      "  \"价钱\": [\"它比其他吹页机稍贵一点，但我认为它的额外功能是值得的。\"]\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "print(response.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'langchain_core.messages.ai.AIMessage'>\n"
     ]
    }
   ],
   "source": [
    "print(type(response))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 175,
   "metadata": {},
   "outputs": [],
   "source": [
    "review_template_2 = \"\"\"\\\n",
    "对于以下文本，请从中提取以下信息：\\\n",
    "    \n",
    "礼物：该商品是作为礼物送给别人的吗？\\\n",
    "如果是，则回答 是的；如果否或未知，则回答不是。\n",
    "\n",
    "交货天数：产品需要多少天到达？如果没有找到该信息，则输出-1。\n",
    "\n",
    "价钱：提取有关价值或价格的任何句子，并将它们输出为逗号分割的python列表。\n",
    "\n",
    "请使用以下键，将输出格式化为JSON：\n",
    "礼物\n",
    "交货天数\n",
    "价钱\n",
    "\n",
    "文本: {text}\n",
    "\n",
    "{format_instructions}\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input_variables=['format_instructions', 'text'] input_types={} partial_variables={} messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['format_instructions', 'text'], input_types={}, partial_variables={}, template='对于以下文本，请从中提取以下信息：\\n礼物：该商品是作为礼物送给别人的吗？如果是，则回答 是的；如果否或未知，则回答不是。\\n\\n交货天数：产品需要多少天到达？如果没有找到该信息，则输出-1。\\n\\n价钱：提取有关价值或价格的任何句子，并将它们输出为逗号分割的python列表。\\n\\n请使用以下键，将输出格式化为JSON：\\n礼物\\n交货天数\\n价钱\\n\\n文本: {text}\\n\\n{format_instructions}'), additional_kwargs={})]\n"
     ]
    }
   ],
   "source": [
    "prompt = ChatPromptTemplate.from_template(review_template_2)\n",
    "print(prompt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.output_parsers import ResponseSchema\n",
    "from langchain.output_parsers import StructuredOutputParser"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [],
   "source": [
    "gift_schema = ResponseSchema(name=\"礼物\", description=\"这件物品是送给别人的礼物吗？如果是，则回答是的，如果不是或位置，则回答不是\")\n",
    "delivery_days_schema = ResponseSchema(name=\"交货天数\",description=\"产品需要多少天才能到达？如果没有找到信息则输出-1\")\n",
    "price_value_schema = ResponseSchema(name=\"价钱\",description=\"提取有关价值或价格的任何句子，并将它们输出为以逗号分割的Python列表\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [],
   "source": [
    "response_schemas = [gift_schema, delivery_days_schema, price_value_schema]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "输出格式规定： The output should be a markdown code snippet formatted in the following schema, including the leading and trailing \"```json\" and \"```\":\n",
      "\n",
      "```json\n",
      "{\n",
      "\t\"礼物\": string  // 这件物品是送给别人的礼物吗？如果是，则回答是的，如果不是或位置，则回答不是\n",
      "\t\"交货天数\": string  // 产品需要多少天才能到达？如果没有找到信息则输出-1\n",
      "\t\"价钱\": string  // 提取有关价值或价格的任何句子，并将它们输出为以逗号分割的Python列表\n",
      "}\n",
      "```\n"
     ]
    }
   ],
   "source": [
    "output_parser = StructuredOutputParser.from_response_schemas(response_schemas)\n",
    "format_instructions =  output_parser.get_format_instructions()\n",
    "print(\"输出格式规定：\",format_instructions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "对于以下文本，请从中提取以下信息：\n",
      "礼物：该商品是作为礼物送给别人的吗？如果是，则回答 是的；如果否或未知，则回答不是。\n",
      "\n",
      "交货天数：产品需要多少天到达？如果没有找到该信息，则输出-1。\n",
      "\n",
      "价钱：提取有关价值或价格的任何句子，并将它们输出为逗号分割的python列表。\n",
      "\n",
      "请使用以下键，将输出格式化为JSON：\n",
      "礼物\n",
      "交货天数\n",
      "价钱\n",
      "\n",
      "文本: 这款吹页机非常神奇。它有四个设置：    吹蜡烛、微风、风城、龙卷风。        两天后就到了，正好赶上我妻子的            两周年纪念礼物。                我想我的妻子会喜欢它到说不出来话。                    到目前为止，我是唯一一个使用过它的人，而且我一直                        每隔一天早上用它来清理草坪上的叶子。                            它比其他吹页机稍贵一点，                                但我认为它的额外功能是值得的。\n",
      "\n",
      "The output should be a markdown code snippet formatted in the following schema, including the leading and trailing \"```json\" and \"```\":\n",
      "\n",
      "```json\n",
      "{\n",
      "\t\"礼物\": string  // 这件物品是送给别人的礼物吗？如果是，则回答是的，如果不是或位置，则回答不是\n",
      "\t\"交货天数\": string  // 产品需要多少天才能到达？如果没有找到信息则输出-1\n",
      "\t\"价钱\": string  // 提取有关价值或价格的任何句子，并将它们输出为以逗号分割的Python列表\n",
      "}\n",
      "```\n"
     ]
    }
   ],
   "source": [
    "message  = prompt.format_messages(text=custom_review, format_instructions = format_instructions)\n",
    "print(message[0].content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = chat.invoke(message)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "```json\n",
      "{\n",
      "\t\"礼物\": \"是的\",\n",
      "\t\"交货天数\": \"2\",\n",
      "\t\"价钱\": \"它比其他吹页机稍贵一点, 但我认为它的额外功能是值得的\"\n",
      "}\n",
      "```\n"
     ]
    }
   ],
   "source": [
    "print(response.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'礼物': '是的', '交货天数': '2', '价钱': '它比其他吹页机稍贵一点, 但我认为它的额外功能是值得的'}"
      ]
     },
     "execution_count": 188,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "output_dict = output_parser.parse(response.content)\n",
    "output_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict"
      ]
     },
     "execution_count": 189,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(output_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
